package com.yuzhitong.shapi.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.ViewGroup;

import com.yuzhitong.shapi.R;


/**
 * loading控件
 *
 * @author MLT
 */
public class LoadingDialog {

    private Dialog loadingDialog;
    private Context context;
    private LoopBackgroundView img;


    public LoadingDialog(Context context) {
        this.context = context;
        initView();
    }

    private void initView() {

        img = new LoopBackgroundView(context);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(100, 100);
        img.setAlpha(.7f);
        // 创建自定义样式的Dialog
        loadingDialog = new Dialog(context, R.style.loading_dialog);
        // 设置返回键无效
        //        loadingDialog.setCancelable(false);
        loadingDialog.setContentView(img, params);
    }


    public void show() {
        loadingDialog.show();
        img.startLoop();
    }

    public void setReturnKey(boolean returnKey) {
        loadingDialog.setCancelable(returnKey);
    }

    public boolean isShowing() {
        return loadingDialog.isShowing();
    }

    public void dismiss() {
        img.stopLoop();
        loadingDialog.dismiss();
    }

}
